using System.Collections.Generic;
using System.Collections.ObjectModel;
using ibba.src.noriskbo.Models;
using ibba.src.noriskbo.ServicePortfolio;

namespace ibba.src.noriskbo.code.translate
{
    public class PortfolioClienteTL
    {
        #region Translate PortfolioClienteDC To PortfolioCliente

        public static void TranslatePortfolioClienteDCToPortfolioCliente(PortfolioClienteDC pRequest, PortfolioCliente pResponse)
        {
            pResponse.IdPortfolioCliente = pRequest.IdPortfolioCliente;
            pResponse.CdContrato = pRequest.CdContrato;
            pResponse.IdCliente = (pRequest.IdCliente == 0) ? 0 : (int?)pRequest.IdCliente;
            pResponse.NoCnpjCpf = pRequest.NoCnpjCpf;
            pResponse.IdVeiculoLegal = (pRequest.IdVeiculoLegal == 0) ? null : (int?)pRequest.IdVeiculoLegal;
            pResponse.NomeCliente = pRequest.NomeCliente;
            pResponse.NomeVeiculoLegal = pRequest.NomeVeiculoLegal;
        }

        public static PortfolioCliente TranslatePortfolioClienteDCToPortfolioCliente(PortfolioClienteDC pRequest)
        {
            PortfolioCliente response = new PortfolioCliente();

            TranslatePortfolioClienteDCToPortfolioCliente(pRequest, response);

            return response;
        }

        public static ObservableCollection<PortfolioCliente> TranslatePortfolioClienteDCToPortfolioCliente(List<PortfolioClienteDC> pRequest)
        {
            ObservableCollection<PortfolioCliente> response = new ObservableCollection<PortfolioCliente>();

            foreach (PortfolioClienteDC item in pRequest)
                response.Add(TranslatePortfolioClienteDCToPortfolioCliente(item));

            return response;
        }

        #endregion

        #region Translate PortfolioCliente To PortfolioClienteDC

        public static void TranslatePortfolioClienteToPortfolioClienteDC(PortfolioCliente pRequest, PortfolioClienteDC pResponse)
        {
            pResponse.IdPortfolioCliente = pRequest.IdPortfolioCliente;
            pResponse.CdContrato = pRequest.CdContrato;
            pResponse.IdCliente = (pRequest.IdCliente == null) ? 0 : (int)pRequest.IdCliente;
            pResponse.NoCnpjCpf = pRequest.NoCnpjCpf;
            pResponse.IdVeiculoLegal = (pRequest.IdVeiculoLegal == null) ? 0 : (int)pRequest.IdVeiculoLegal;
            pResponse.NomeCliente = pRequest.NomeCliente;
            pResponse.NomeVeiculoLegal = pRequest.NomeVeiculoLegal;
        }

        public static PortfolioClienteDC TranslatePortfolioClienteToPortfolioClienteDC(PortfolioCliente pRequest)
        {
            PortfolioClienteDC response = new PortfolioClienteDC();

            TranslatePortfolioClienteToPortfolioClienteDC(pRequest, response);

            return response;
        }

        public static List<PortfolioClienteDC> TranslatePortfolioClienteToPortfolioClienteDC(ObservableCollection<PortfolioCliente> pRequest)
        {
            List<PortfolioClienteDC> response = new List<PortfolioClienteDC>();

            foreach (PortfolioCliente item in pRequest)
                response.Add(TranslatePortfolioClienteToPortfolioClienteDC(item));

            return response;
        }

        #endregion

        #region Translate PortfolioClienteGrid To PortfolioClienteDC

        public static void TranslatePortfolioClienteToPortfolioClienteDC(PortfolioClienteGrid pRequest, PortfolioClienteDC pResponse)
        {
            pResponse.IdPortfolioCliente = pRequest.IdPortfolioCliente;
            pResponse.CdContrato = pRequest.CdContrato;
            pResponse.IdCliente = (pRequest.IdCliente == null) ? 0 : (int)pRequest.IdCliente;
            pResponse.NoCnpjCpf = pRequest.NoCnpjCpf;
            pResponse.IdVeiculoLegal = (pRequest.IdVeiculoLegal == null) ? 0 : (int)pRequest.IdVeiculoLegal;
            pResponse.NomeCliente = pRequest.NomeCliente;
            pResponse.NomeVeiculoLegal = pRequest.NomeVeiculoLegal;

            switch (pRequest.StatusImportacao)
            {
                case ibba.src.noriskbo.Constantes.StatusPortfolioImportLote.GRAVADO:
                    pResponse.StatusImportacao = 0;
                    break;

                case ibba.src.noriskbo.Constantes.StatusPortfolioImportLote.INCLUSAO:
                    pResponse.StatusImportacao = 1;
                    break;

                case ibba.src.noriskbo.Constantes.StatusPortfolioImportLote.INCLUSAO_AVISO:
                    pResponse.StatusImportacao = 1;
                    break;

                case ibba.src.noriskbo.Constantes.StatusPortfolioImportLote.ALTERACAO:
                    pResponse.StatusImportacao = 2;
                    break;

                case ibba.src.noriskbo.Constantes.StatusPortfolioImportLote.ALTERACAO_AVISO:
                    pResponse.StatusImportacao = 2;
                    break;

                case ibba.src.noriskbo.Constantes.StatusPortfolioImportLote.EXCLUSAO:
                    pResponse.StatusImportacao = 3;
                    break;

                default:
                    pResponse.StatusImportacao = 0;
                    break;
            }
        }

        public static PortfolioClienteDC TranslatePortfolioClienteToPortfolioClienteDC(PortfolioClienteGrid pRequest)
        {
            PortfolioClienteDC response = new PortfolioClienteDC();

            TranslatePortfolioClienteToPortfolioClienteDC(pRequest, response);

            return response;
        }

        public static List<PortfolioClienteDC> TranslatePortfolioClienteToPortfolioClienteDC(ObservableCollection<PortfolioClienteGrid> pRequest)
        {
            List<PortfolioClienteDC> response = new List<PortfolioClienteDC>();

            foreach (PortfolioClienteGrid item in pRequest)
                response.Add(TranslatePortfolioClienteToPortfolioClienteDC(item));

            return response;
        }

        #endregion
    }
}
